import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import eslintPlugin from "vite-plugin-eslint";
import nightwatchPlugin from "vite-plugin-nightwatch";
import * as path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: [
        "vue",
        "vue-router",
        {
          "naive-ui": [
            "useDialog",
            "useLoadingBar",
            "useMessage",
            "useNotification",
          ],
        },
      ],
      dts: true, // typescript support for auto import components.
      eslintrc: {
        enabled: true, // 允许eslint
      },
    }),
    Components({
      resolvers: [NaiveUiResolver()], // 按需按需自动加载Naive Ui 的组件.
      dts: true, // typescript support for auto import components.
    }),
    eslintPlugin({ cache: false }),
    nightwatchPlugin(),
  ],
  server: {
    host: "0.0.0.0",
    port: 8888,
    open: true,
    proxy: {
      "/api": {
        target: "http://localhost:8080",
        changeOrigin: true, // 是否改变域名
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  resolve: {
    alias: {
      "@": path.join(__dirname, "./src"),
    },
  },
});
